﻿using Rhino;
using Rhino.Commands;
using System;
using YangTools.Realization;

namespace YangTools
{
    public class LayerRandomMaterialCommand : Command
    {
        static LayerRandomMaterialCommand _instance;
        public LayerRandomMaterialCommand()
        {
            _instance = this;
        }

        ///<summary>The only instance of the LayerRandomMaterialCommand command.</summary>
        public static LayerRandomMaterialCommand Instance
        {
            get { return _instance; }
        }

        public override string EnglishName
        {
            get { return "LayerRandomMaterial"; }
        }

        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var go = new Rhino.Input.Custom.GetOption();
            var t = new Rhino.Input.Custom.OptionToggle(true, "不改变", "改变");
            go.AddOptionToggle("是否改变已有材质", ref t);
            go.AcceptNothing(true);
            var r = go.Get();

            bool changeExisting = true;
            if (r == Rhino.Input.GetResult.Option) changeExisting = t.CurrentValue;

            LayerAttributes la = new LayerAttributes();
            int count = la.RangeMaterial(changeExisting);
            RhinoApp.WriteLine($"成功改变 {count} 个图层的材质！");
            return Result.Success;
        }
    }
}